home *** CD-ROM | disk | FTP | other *** search
- Path: news.axess.com!news
- From: tdrymona@axess.com (Kamikaze)
- Newsgroups: comp.lang.c++
- Subject: Re: Help: File counting lines
- Date: Sun, 10 Mar 1996 17:18:04 GMT
- Organization: Axess Communications, Montreal, Canada
- Message-ID: <4huog1$t8s@news.axess.com>
- References: <4hni12$qst@bolivia.it.earthlink.net>
- Reply-To: tdrymona@axess.com
- NNTP-Posting-Host: cretien.axess.com
- X-Newsreader: Forte Free Agent v0.55
-
- brunop@earthlink.net (Peter Bruno) wrote:
-
- >Does anyone have any suggestions on a fast way to count the number of lines in
- >a ASCII file. Each line is terminted by a <enter> and all I need to do is
- >count the number of lines (records) in the file.
-
- >The way I've been doing it is by: fgets(row, 128, File); count++;
- >however, if the line is longer then 128 characters this does not work and it
- >would seem that there must be a better way of doing it anyway... perhaps by
- >incrementing the pointer until EOF??
-
- >Any assistance would be greatly appreciated...
-
- >Thanx,
-
- >Peter Bruno
- >brunop@earthlink.net
-
- Yeah use the stream objects, like this
-
- ifstream in;
- int count = 0;
- char buffer[BUFFER_SIZE );
-
- in = open( name_of_file );
- if ( !in.bad() )
- {
- while ( !in.eof() )
- {
- getline( buffer, sizeof( buffer ) );
- count++;
- }
- in.close();
- }
-
-
- Something like this, you get the picture.
-
-
-